package cn.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author jia
 * @Description
 * @date 2019-03-21-10:54
 */
public class DaoCount {
    public static int count(String sql) {
        int total = 0;
        try (Connection connection = DaoUtil.getConnection();
             Statement statement = connection.createStatement()) {
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                total = rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return total;
    }
}
